<?php defined('SYSPATH') or die('No direct script access.');

	class Model_Services_Test extends Model implements Jqgrid_GridListener{
		
		private $aTest;
			
		public function count($criteria = false){
			return ORM::factory("dao_test")->count_all();
		}
		
		public function getList($criteria = false){
			if (!$criteria)	$test_list = ORM::factory("dao_test")->find_all()->as_array();
			$test_list = ORM::factory("dao_test")->order_by($criteria->sidx,$criteria->sord)->limit($criteria->limit)->find_all()->as_array();
	
			$dataset = array();
			foreach ($test_list as $test){
				$dataset[$test->id] = array($test->test_data);
			}
			
			return $dataset;
		}
	
		
		public function get($id){
			return ORM::factory("dao_test")->find($id);
		}
		
		public function save($id, array $data){
			$aTest = ($id > 0)? ORM::factory("dao_test",$id) : ORM::factory("dao_test");
			$aTest->test_data = $data['test_data'];
			$aTest->save();
			return "Test ".$id." guardado con exito";
		}
		
		public function delete($id){
			$aTest = ORM::factory("dao_test",$id);
			$aTest->delete();
			return "Test ".$id." eliminado con exito";
		}
		
		
	}
?>
